import Sequelize from 'sequelize';

const fs = require('fs');
const allFiles: any = fs.readdirSync(__dirname);
const {STRING, INTEGER, DATE} = Sequelize;
const allModelFile = allFiles.filter((fileItem: any) => fileItem.endsWith('.js') && fileItem !== 'index.js');
const modelList: any = [];
allModelFile.forEach((file: any) => {
    const model = require(`${__dirname}/${file}`);
    model[0]=file.replace('.js','');
    if (!model[1].createdAt) {
        model[1].createdAt = {
            type: DATE,
            defaultValue: new Date()
        };
        model[1].updatedAt = {
            type: DATE,
            defaultValue: new Date()
        };
        model[1].deleteAt = {
            type: DATE,
            allowNull: true,
            defaultValue: null
        };
    }
    modelList.push(model);
});
module.exports = modelList;
